//
//  JXEmoticonToolBarView.swift
//  swift高仿微博
//
//  Created by peijiaxing on 16/3/9.
//  Copyright © 2016年 peijiaxing. All rights reserved.
//

import UIKit

class JXEmoticonToolBarView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(recentButton)
        addSubview(defaultButton)
        addSubview(emojiButton)
        addSubview(lxhButton)
        
        // 添加约束
        recentButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(defaultButton.snp_width)
        }
        
        defaultButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(recentButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(emojiButton.snp_width)
            
        }
        
        emojiButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(defaultButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(lxhButton.snp_width)
        }
        
        lxhButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(emojiButton.snp_right)
            
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.right.equalTo(self.snp_right)
            
        }
    }
    
    
    
    @objc private func changeEmoticon(button: UIButton){
        
        
        for subView in self.subviews{
            
            let button = subView as! UIButton
            
            button.selected = false
            
        }
        
        button.selected = true
    }

    
    
    // MARK: -- 懒加载
    // 最近
    private lazy var recentButton:UIButton  = {
       let button = UIButton(type: UIButtonType.Custom)
        button.setTitle("最近", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        button.addTarget(self, action: "changeEmoticon:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
        
    }()
    // 默认表情
    private lazy var defaultButton:UIButton = {
       let button = UIButton(type: UIButtonType.Custom)
        button.setTitle("默认", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        button.addTarget(self, action: "changeEmoticon:", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    // emoji
    private lazy var emojiButton:UIButton = {
       
        let button = UIButton(type: UIButtonType.Custom)
        button.setTitle("EMOJI", forState: UIControlState.Normal)
        button.setImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        button.addTarget(self, action: "changeEmoticon:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    // 浪小花
    private lazy var lxhButton:UIButton = {
       
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("浪小花", forState: UIControlState.Normal)
        button.setImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        
        button.addTarget(self, action: "changeEmoticon:", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
}
